//index.js  
//获取应用实例  
var app = getApp(), t = app.requirejs("core"), a = app.requirejs("wxParse/wxParse"), i = app.requirejs("biz/diypage");
Page({
  data: {
    /** 
        * 页面配置 
        */
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: 0,




  },
  onShow: function () {
    var that = this;

    /** 
     * 获取系统信息 
     */
    wx.getSystemInfo({

      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });
    t.get("member", {}, function (e) {
      0 != e.error ? wx.redirectTo({
        url: "/pages/message/auth/index"
      }) : (that.setData({
        userInfo: e,
        canTakeCash: e.takeCash.canTakeCash
      }))
    });
  },
  /** 
     * 滑动切换tab 
     */
  bindChange: function (e) {

    var that = this;
    that.setData({ currentTab: e.detail.current });

  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  takeAll:function(){
    var that = this;
    this.setData({
      money: that.data.canTakeCash
    })
  },
  changeMoney:function(e){
    console.log(e)
    this.setData({ money: e.detail.value})
  },
  changeAccount: function (e) {
    console.log(e)
    this.setData({ account: e.detail.value })
  },
  changePhone: function (e) {
    console.log(e)
    this.setData({ phone: e.detail.value })
  },
  applyAgentTakeMoney:function(){
    if(this.checkForm()){
      var sendData = {
        account: this.data.account,
        phone: this.data.phone,
        money: this.data.money,
        type: Number(this.data.currentTab)+1,
      };
      t.get("member/index/applyAgentTakeMoney", sendData, function (e) {
        if(e==1) wx.showToast({
          title: '申请成功',
        }),wx.navigateBack({
          
        })
      });
    }
  },
  checkForm:function(){
    var data = this.data,res=true;
    if (!data.account) this.diyAlert("请填写账号信息"),res=false;
    if (!data.phone || !/^1[3|5|8]\d{9}$/.test(data.phone)) this.diyAlert("请填写电话信息"), res = false;
    if (!data.money) this.diyAlert("请填写提现金额"), res = false;
    if (data.money < 100) this.diyAlert("提现金额需要大于100"), res = false;
    if (data.money > data.canTakeCash) this.diyAlert("没有足够的金额"), res = false;
    return res;
  },
  diyAlert:function(msg){
    wx.showToast({
      title: msg,
    })
  }
})  